package com.lxl.hadoop.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2021/12/31 19:54
 * @Description
 */
public class SortMapper extends Mapper<LongWritable,Text,FlowBean,Text> {
    FlowBean flowBean = new FlowBean();
    Text phone = new Text();
    Long up = null;
    Long down = null;
    protected void map(LongWritable key, Text value,
                       Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] words = line.split("\t");
        phone.set(words[1]);
         up = Long.valueOf(words[words.length - 3]);
         down = Long.valueOf(words[words.length - 2]);
        flowBean.setUpFlow(up);
        flowBean.setDownFlow(down);
        flowBean.setSumFlow(up+down);
        context.write(flowBean,phone);
    }
}
